//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace;

import android.text.TextUtils;
import com.baidu.trace.a.h;
import com.baidu.trace.ar.a;
import com.baidu.trace.c.g;
import java.util.Deque;
import java.util.LinkedList;
import org.json.JSONObject;

public class aw implements g {
    private static byte d = 1;
    private static Deque<a> e = null;
    public static Deque<a> a = null;
    private static int f = 0;
    protected static long b = 2L;
    protected static int c = 0;
    private static String g = "";

    public aw() {
    }

    protected static void b() {
        if(e == null) {
            e = new LinkedList();
        }

        if(a == null) {
            a = new LinkedList();
        }

    }

    public final void a() {
        b();
        f = 0;
        if(a.size() > 0) {
            this.a(a);
        } else {
            label24: {
                if(bd.g || !bd.d && bd.h) {
                    LinkedList var2 = new LinkedList();
                    g = am.a(z.c, 10, var2);
                    if(c > 0) {
                        this.a((Deque)var2);
                        break label24;
                    }
                }

                g = z.c;
                this.a(bd.c);
            }
        }

        TraceJniInterface.a().setPackData(d, e());
    }

    private void a(Deque<a> var1) {
        int var2 = d == 1?(z.r << 5) * 3:z.r << 5;
        int var3 = var1.size();

        while(f < var2 && var3 > 0 && e.size() < 10) {
            a var4 = (a)var1.poll();
            --var3;
            if(var4 != null && var4.b != null) {
                if(var2 - f < var4.b.length) {
                    var1.offerFirst(var4);
                    return;
                }

                e.offer(var4);
                f += var4.b.length;
            }
        }

    }

    private static byte[] e() {
        int var0 = 0;
        byte[] var1 = new byte[f];
        int var2 = e.size();

        for(int var3 = 0; var3 < var2; ++var3) {
            a var4 = (a)e.poll();
            if(var4 != null && var4.b != null) {
                if(var0 + var4.b.length > var1.length) {
                    return var1;
                }

                for(int var5 = 0; var5 < var4.b.length; ++var5) {
                    var1[var0 + var5] = var4.b[var5];
                }

                var0 += var4.b.length;
                e.offer(var4);
            }
        }

        return var1;
    }

    public static void a(int var0) {
        if(z.s == 1) {
            LinkedList var1 = new LinkedList();

            while(e.size() > 0) {
                a var2 = (a)e.poll();
                var1.offer(var2);
            }

            bd.a(var0, var1);
        }

        f = 0;
    }

    public static void c() {
        while(e.size() > 0) {
            a var0 = (a)e.poll();
            a.offerLast(var0);
        }

        f = 0;
    }

    public static void b(int var0) {
        if(var0 > 0) {
            if((bd.g || !bd.d && bd.h) && c > 0 && !TextUtils.isEmpty(g)) {
                am.a(g, c);
            }

            bd.a(var0);
        }
    }

    public final void a(JSONObject var1) {
        h var2 = new h();

        try {
            var2.a = var1.getInt("msg_flag");
            bc.a();
            bc.a(var2);
        } catch (Exception var5) {
            ;
        } finally {
            ;
        }
    }

    protected static void d() {
        if(e != null) {
            e.clear();
            e = null;
        }

        if(a != null) {
            a.clear();
            a = null;
        }

    }
}
